/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.news.server.check.checkers;

import cn.ac.iie.di.ban.news.server.check.CheckResult;
import cn.ac.iie.di.ban.news.server.check.Checker;

/**
 *
 * @author zwlin
 */
public class IpChecker implements Checker<String, String> {

	private static final Exception exp = new Exception();

	@Override
	public CheckResult check(String src, String target) {
		try {
			String[] dvd = src.split("\\.");
			if (dvd == null || dvd.length != 4) {
				throw exp;
			}
			for (String s : dvd) {
				int i = Integer.parseInt(s);
				if (i < 0 || i > 255) {
					throw exp;
				}
			}
		} catch (Exception e) {
			return new CheckResult("ip format error.");
		}
		return new CheckResult();
	}

}
